package org.bigdata.framework.core.protocol;

import java.util.HashMap;
import java.util.List;

import org.bigdata.framework.core.model.GeneralWord;
import org.bigdata.framework.core.model.GeneralWordCategory;
import org.bigdata.framework.core.model.ThesauriWord;
import org.bigdata.framework.core.model.ThesauriWordCategory;
import org.bigdata.framework.core.model.ThesauriWordModule;
import org.bigdata.framework.core.model.ThesauriWordReference;
import org.bigdata.framework.core.model.ThesauriWordRelation;
import org.bigdata.framework.core.service.IGeneralWordCategoryService;
import org.bigdata.framework.core.service.IGeneralWordService;
import org.bigdata.framework.core.service.IThesauriWordCategoryService;
import org.bigdata.framework.core.service.IThesauriWordModuleService;
import org.bigdata.framework.core.service.IThesauriWordReferenceService;
import org.bigdata.framework.core.service.IThesauriWordRelationService;
import org.bigdata.framework.core.service.IThesauriWordService;
import org.bigdata.framework.core.utils.MybatisPlusTools;
import org.springframework.beans.factory.annotation.Autowired;

import com.baomidou.mybatisplus.plugins.Page;

/**
 * 2016-10-26 16:50:50
 * 
 * @author vimes
 * 
 */
public class WordService implements IWordService {

	@Autowired
	private IGeneralWordCategoryService generalWordCategoryService;
	@Autowired
	private IGeneralWordService generalWordService;
	@Autowired
	private IThesauriWordCategoryService thesauriWordCategoryService;
	@Autowired
	private IThesauriWordReferenceService thesauriWordReferenceService;
	@Autowired
	private IThesauriWordService thesauriWordService;
	@Autowired
	private IThesauriWordModuleService thesauriWordModuleService;
	@Autowired
	private IThesauriWordRelationService thesauriWordRelationService;

	@Override
	public GeneralWordCategory saveGeneralWordCategory(
			GeneralWordCategory generalWordCategory) {

		boolean r = generalWordCategoryService.insert(generalWordCategory);
		if (r) {
			return generalWordCategory;
		}
		return null;
	}

	@Override
	public GeneralWordCategory editGeneralWordCategory(
			GeneralWordCategory generalWordCategory) {

		boolean r = generalWordCategoryService.updateAllColumnById(generalWordCategory);
		if (r) {
			return generalWordCategory;
		}
		return null;
	}

	@Override
	public void deleteGeneralWordCategory(
			GeneralWordCategory generalWordCategory) {

		boolean r = generalWordCategoryService.deleteById(generalWordCategory
				.getId());
		if (r) {
			System.out.println("generalWordCategory 删除成功>>>"
					+ generalWordCategory.getId());
		}
	}

	@Override
	public GeneralWord saveGeneralWord(GeneralWord generalWord) {

		boolean r = generalWordService.insert(generalWord);
		if (r) {
			return generalWord;
		}
		return null;
	}

	@Override
	public GeneralWord editGeneralWord(GeneralWord generalWord) {

		boolean r = generalWordService.updateAllColumnById(generalWord);
		if (r) {
			return generalWord;
		}
		return null;
	}

	@Override
	public void deleteGeneralWord(GeneralWord generalWord) {

		boolean r = generalWordService.deleteById(generalWord.getId());
		if (r) {
			System.out.println("generalWord 删除成功>>>" + generalWord.getId());
		}
	}

	@Override
	public ThesauriWordCategory saveThesauriWordCategory(
			ThesauriWordCategory thesauriWordCategory) {

		boolean r = thesauriWordCategoryService.insert(thesauriWordCategory);
		if (r) {
			return thesauriWordCategory;
		}
		return null;
	}

	@Override
	public ThesauriWordCategory editThesauriWordCategory(
			ThesauriWordCategory thesauriWordCategory) {

		boolean r = thesauriWordCategoryService
				.updateAllColumnById(thesauriWordCategory);
		if (r) {
			return thesauriWordCategory;
		}
		return null;
	}

	@Override
	public void deleteThesauriWordCategory(
			ThesauriWordCategory thesauriWordCategory) {

		boolean r = thesauriWordCategoryService.deleteById(thesauriWordCategory
				.getId());
		if (r) {
			System.out.println("thesauriWordCategory 删除成功>>>"
					+ thesauriWordCategory.getId());
		}
	}

	@Override
	public ThesauriWord saveThesauriWord(ThesauriWord thesauriWord) {

		boolean r = thesauriWordService.insert(thesauriWord);
		if (r) {
			return thesauriWord;
		}
		return null;
	}

	@Override
	public ThesauriWord editThesauriWord(ThesauriWord thesauriWord) {

		boolean r = thesauriWordService.updateAllColumnById(thesauriWord);
		if (r) {
			return thesauriWord;
		}
		return null;
	}

	@Override
	public void deleteThesauriWord(ThesauriWord thesauriWord) {

		boolean r = thesauriWordService.deleteById(thesauriWord.getId());
		if (r) {
			System.out.println("thesauriWord 删除成功>>>" + thesauriWord.getId());
		}
	}

	@Override
	public ThesauriWordReference saveThesauriWordReference(
			ThesauriWordReference thesauriWordReference) {

		boolean r = thesauriWordReferenceService.insert(thesauriWordReference);
		if (r) {
			return thesauriWordReference;
		}
		return null;
	}

	@Override
	public ThesauriWordReference editThesauriWordReference(
			ThesauriWordReference thesauriWordReference) {

		boolean r = thesauriWordReferenceService
				.updateAllColumnById(thesauriWordReference);
		if (r) {
			return thesauriWordReference;
		}
		return null;
	}

	@Override
	public void deleteThesauriWordReference(
			ThesauriWordReference thesauriWordReference) {

		boolean r = thesauriWordReferenceService
				.deleteById(thesauriWordReference.getId());
		if (r) {
			System.out.println("thesauriWordReference 删除成功>>>"
					+ thesauriWordReference.getId());
		}
	}

	@Override
	public GeneralWordCategory findGeneralWordCategory(Integer id) {

		return generalWordCategoryService.selectById(id);
	}

	@Override
	public List<GeneralWordCategory> getGeneralWordCategory() {

		return generalWordCategoryService.selectList(null);
	}
	
	@Override
	public List<GeneralWordCategory> getGeneralWordCategory(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {
		return generalWordCategoryService.selectPage(
				new Page<GeneralWordCategory>(pageNumber, pageSize),
				new MybatisPlusTools<GeneralWordCategory>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getGeneralWordCategoryCount(
			HashMap<String, Object> queryParams) {
		return generalWordCategoryService
				.selectCount(new MybatisPlusTools<GeneralWordCategory>()
						.getEwByCount(queryParams));
	}
	
	@Override
	public GeneralWord findGeneralWord(Integer id) {

		return generalWordService.selectById(id);
	}

	@Override
	public GeneralWord getGeneralWordByName(HashMap<String, Object> queryParams) {
		GeneralWord generalWord = null;
		List<GeneralWord> generalWords = generalWordService.selectPage(
				new Page<GeneralWord>(1, 1),
				new MybatisPlusTools<GeneralWord>().getEwByList(queryParams))
				.getRecords();
		if (generalWords.size() > 0) {
			generalWord = generalWords.get(0);
		}

		return generalWord;
	}

	@Override
	public List<GeneralWord> getGeneralWord(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {

		return generalWordService.selectPage(
				new Page<GeneralWord>(pageNumber, pageSize),
				new MybatisPlusTools<GeneralWord>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getGeneralWordCount(HashMap<String, Object> queryParams) {

		return generalWordService
				.selectCount(new MybatisPlusTools<GeneralWord>()
						.getEwByCount(queryParams));
	}

	@Override
	public List<ThesauriWordCategory> getThesauriWordCategory() {

		return thesauriWordCategoryService.selectList(null);
	}

	@Override
	public ThesauriWordCategory findThesauriWordCategory(Integer id) {

		return thesauriWordCategoryService.selectById(id);
	}

	@Override
	public List<ThesauriWordCategory> getThesauriWordCategory(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {

		return thesauriWordCategoryService.selectPage(
				new Page<ThesauriWordCategory>(pageNumber, pageSize),
				new MybatisPlusTools<ThesauriWordCategory>()
						.getEwByList(queryParams)).getRecords();
	}

	@Override
	public Integer getThesauriWordCategoryCount(
			HashMap<String, Object> queryParams) {

		return thesauriWordCategoryService
				.selectCount(new MybatisPlusTools<ThesauriWordCategory>()
						.getEwByCount(queryParams));
	}

	@Override
	public List<ThesauriWord> getThesauriWord() {

		return thesauriWordService.selectList(null);
	}

	@Override
	public ThesauriWord findThesauriWord(Integer id) {

		return thesauriWordService.selectById(id);
	}

	@Override
	public ThesauriWord getThesauriWordByName(
			HashMap<String, Object> queryParams) {
		ThesauriWord thesauriWord = null;
		List<ThesauriWord> thesauriWords = thesauriWordService.selectPage(
				new Page<ThesauriWord>(1, 1),
				new MybatisPlusTools<ThesauriWord>().getEwByList(queryParams))
				.getRecords();
		if (thesauriWords.size() > 0) {
			thesauriWord = thesauriWords.get(0);
		}

		return thesauriWord;
	}

	@Override
	public List<ThesauriWord> getThesauriWord(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {

		return thesauriWordService.selectPage(
				new Page<ThesauriWord>(pageNumber, pageSize),
				new MybatisPlusTools<ThesauriWord>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getThesauriWordCount(HashMap<String, Object> queryParams) {

		return thesauriWordService
				.selectCount(new MybatisPlusTools<ThesauriWord>()
						.getEwByCount(queryParams));
	}

	@Override
	public List<ThesauriWordReference> getThesauriWordReference() {

		return thesauriWordReferenceService.selectList(null);
	}

	@Override
	public ThesauriWordReference findThesauriWordReference(Integer id) {

		return thesauriWordReferenceService.selectById(id);
	}

	@Override
	public List<ThesauriWordReference> getThesauriWordReference(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {

		return thesauriWordReferenceService.selectPage(
				new Page<ThesauriWordReference>(pageNumber, pageSize),
				new MybatisPlusTools<ThesauriWordReference>()
						.getEwByList(queryParams)).getRecords();
	}

	@Override
	public Integer getThesauriWordReferenceCount(
			HashMap<String, Object> queryParams) {

		return thesauriWordReferenceService
				.selectCount(new MybatisPlusTools<ThesauriWordReference>()
						.getEwByCount(queryParams));
	}

    @Override
    public ThesauriWordModule saveThesauriWordModule(ThesauriWordModule thesauriWordModule) {
        boolean r = thesauriWordModuleService.insert(thesauriWordModule);
        if (r) {
            return thesauriWordModule;
        }
        return null;
    }

    @Override
    public ThesauriWordModule editThesauriWordModule(ThesauriWordModule thesauriWordModule) {
        boolean r = thesauriWordModuleService.updateAllColumnById(thesauriWordModule);
        if (r) {
            return thesauriWordModule;
        }
        return null;
    }

    @Override
    public void deleteThesauriWordModule(ThesauriWordModule thesauriWordModule) {
        boolean r = thesauriWordModuleService.deleteById(thesauriWordModule.getId());
        if (r) {
            System.out.println("thesauriWordModule 删除成功>>>"+ thesauriWordModule.getId());
        }
        
    }
    
    @Override
    public ThesauriWordRelation saveThesauriWordRelation(ThesauriWordRelation thesauriWordRelation) {
        boolean r = thesauriWordRelationService.insert(thesauriWordRelation);
        if (r) {
            return thesauriWordRelation;
        }
        return null;
    }

    @Override
    public ThesauriWordRelation editThesauriWordRelation(ThesauriWordRelation thesauriWordRelation) {
        boolean r = thesauriWordRelationService.updateAllColumnById(thesauriWordRelation);
        if (r) {
            return thesauriWordRelation;
        }
        return null;
    }

    @Override
    public void deleteThesauriWordRelation(ThesauriWordRelation thesauriWordRelation) {
        boolean r = thesauriWordRelationService.deleteById(thesauriWordRelation.getId());
        if (r) {
            System.out.println("thesauriWordRelation 删除成功>>>"+ thesauriWordRelation.getId());
        }
        
    }

    @Override
    public List<ThesauriWordModule> getThesauriWordModule() {
        return thesauriWordModuleService.selectList(null);
    }

    @Override
    public ThesauriWordModule findThesauriWordModule(Integer id) {
        return thesauriWordModuleService.selectById(id);
    }

    @Override
    public List<ThesauriWordModule> getThesauriWordModule(HashMap<String, Object> queryParams, int pageNumber, int pageSize) {
        return thesauriWordModuleService.selectPage(
                new Page<ThesauriWordModule>(pageNumber, pageSize),
                new MybatisPlusTools<ThesauriWordModule>()
                        .getEwByList(queryParams)).getRecords();
    }

    @Override
    public Integer getThesauriWordModuleCount(HashMap<String, Object> queryParams) {
        return thesauriWordModuleService
                .selectCount(new MybatisPlusTools<ThesauriWordModule>()
                        .getEwByCount(queryParams));
    }
    
    @Override
    public List<ThesauriWordRelation> getThesauriWordRelation() {
        return thesauriWordRelationService.selectList(null);
    }

    @Override
    public ThesauriWordRelation findThesauriWordRelation(Integer id) {
        return thesauriWordRelationService.selectById(id);
    }

    @Override
    public List<ThesauriWordRelation> getThesauriWordRelation(HashMap<String, Object> queryParams, int pageNumber, int pageSize) {
        return thesauriWordRelationService.selectPage(
                new Page<ThesauriWordRelation>(pageNumber, pageSize),
                new MybatisPlusTools<ThesauriWordRelation>()
                        .getEwByList(queryParams)).getRecords();
    }

    @Override
    public Integer getThesauriWordRelationCount(HashMap<String, Object> queryParams) {
        return thesauriWordRelationService
                .selectCount(new MybatisPlusTools<ThesauriWordRelation>()
                        .getEwByCount(queryParams));
    }

}
